package com.neusoft.shopping.manager.dao;

import com.neusoft.shopping.manager.entity.TypeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository
public class TypeDAOImpl {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    RowMapper<TypeEntity> rowMapper=new BeanPropertyRowMapper(TypeEntity.class);

    public List<TypeEntity> qureyAll(){
        String sql="select *from typeinfo";
        return jdbcTemplate.query(sql,rowMapper);
    }
    public TypeEntity qureyByTypeno(Integer typeno){
        String sql="select *from typeinfo where typeno=?";
        return jdbcTemplate.queryForObject(sql,rowMapper,typeno);
    }
    public int add_type(TypeEntity type){
        String sql="insert into typeinfo values (null,?)";
        return jdbcTemplate.update(sql,type.getTypename());
    }
    public int update_type(TypeEntity type){
        String sql="update typeinfo set typename=? where typeno=?";
        return jdbcTemplate.update(sql,type.getTypename(),type.getTypeno());
    }
    public int del_type(Integer typeno){
        String sql="delete from typeinfo where typeno=?";
        return jdbcTemplate.update(sql,typeno);
    }
}
